package com.flight.trans.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.EnterPortTakeBean.EnterPortTakeData;

import java.util.List;

/**
 * 出港提货
 */
public class EnterPortTakeAdapter extends BaseRecyclerAdapter<EnterPortTakeData> {

    private int IsChecked ;

    public EnterPortTakeAdapter(Context mContext, List<EnterPortTakeData> mList , int IsChecked) {
        super(mContext, mList);
        this.IsChecked = IsChecked ;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_enter_take;
    }

    @Override
    protected void bindData(BaseViewHolder holder, EnterPortTakeData data, int position) {
        LinearLayout mLlContainerItem = holder.findViewById(R.id.mLlContainerItem);

        TextView mTvTakeNo = holder.findViewById(R.id.mTvTakeNo);
        TextView mTvOrderCount = holder.findViewById(R.id.mTvOrderCount);
        TextView mTvTotalCount = holder.findViewById(R.id.mTvTotalCount);
        TextView mTvTotalWeight = holder.findViewById(R.id.mTvTotalWeight);
        TextView mTvPickingPersonnel = holder.findViewById(R.id.mTvPickingPersonnel);
        TextView mTvTakeChannel = holder.findViewById(R.id.mTvTakeChannel);
        TextView mTvReceiver = holder.findViewById(R.id.mTvReceiver);
        TextView mTvTakePersonnel = holder.findViewById(R.id.mTvTakePersonnel);
        TextView mTvTakeTime = holder.findViewById(R.id.mTvTakeTime);

        mTvTakeNo.setText(data.getConsigneeNo());
        mTvOrderCount.setText(String.valueOf(data.getOrderCnt()));
        mTvTotalCount.setText(String.valueOf(data.getRealNumber()));
        mTvTotalWeight.setText(String.valueOf(data.getRealWeight()));
        mTvPickingPersonnel.setText(data.getOutboundUser());
        mTvReceiver.setText(data.getReceiverName());
        mTvTakePersonnel.setText(IsChecked == 0 ? data.getReceiverName() : data.getConsigneeName());

        mTvTakeChannel.setVisibility(IsChecked == 0 ? View.GONE : View.VISIBLE);
        mTvTakeChannel.setText(data.getDeliveryChannel());

        mTvTakeTime.setVisibility(IsChecked != 2 ? View.GONE : View.VISIBLE);
        mTvTakeTime.setText(data.getTakeDeliveryTime());

        mLlContainerItem.setBackground(mContext.getDrawable(data.isLocked() ? R.color.color_red : R.drawable.selector_cyan_line));

        setOnItemClickListener(mLlContainerItem , position);
    }

    public void updateAdapter(List<EnterPortTakeData> mList , int IsChecked){
        this.IsChecked = IsChecked ;
        updateAdapter(mList);
    }
}
